<?php
/**
* @version 1.0.0
* @package RSSearch! 1.0.0
* @copyright (C) 2011 www.rsjoomla.com
* @license GPL, http://www.gnu.org/licenses/gpl-2.0.html
*/
defined('_JEXEC') or die('Restricted access');
$document -> addStyleSheet(JURI::root().'modules/mod_rssearch/assets/css/rssearch.css','text/css', 'screen');
$document -> addScript(JURI::root().'modules/mod_rssearch/assets/js/ajax.js');
?>
<script type="text/javascript" charset="utf-8">
	var moduleId = <?php echo $module->id;?>;
	var RSFSearch<?php echo $module->id;?>;

var results_box = document.getElementById('search_suggest<?php echo $module->id;?>');
var searchReq = getXmlHttpRequestObject();

function searchSuggest<?php echo $module->id;?>(){
	if(searchReq.readyState == 4 || searchReq.readyState == 0){
		var str = escape(document.getElementById('rsf_inp<?php echo $module->id;?>').value);
		searchReq.open("GET", '<?php echo JURI::root(true); ?>/index.php?option=com_rssearch&view=results&layout=ajax&module_id=<?php echo $module->id;?>&search='+str, true);
		searchReq.onreadystatechange = function(){
			if(searchReq.readyState == 4){
				var ss = document.getElementById('search_suggest<?php echo $module->id;?>')

				ss.innerHTML = '';
				if (searchReq.responseText.indexOf('---RSSEARCH_SEPARATOR---') > -1){
					var str = searchReq.responseText.split("---RSSEARCH_SEPARATOR---");
					var suggest = '';
					var results = str.length;
					var limit = <?php echo $limit;?>;
				
					if(results < limit){
						var max = results;
					}else {
						var max = limit;
					}

					for(i=0; i<max; i++){
						suggest += '<div onmouseover="javascript:suggestOver<?php echo $module->id;?>(this);" ';
						suggest += 'onmouseout="javascript:suggestOut<?php echo $module->id;?>(this);"';
						suggest += 'class="suggest_link">' + str[i] + '</div>';
					}
					if(results > limit){
						suggest += '<p style="text-align:center;cursor:pointer;" onclick="javascript:setSearch<?php echo $module->id;?>(this.innerHTML);"><?php echo JText::_("RSF_MODULE_VIEW_ALL_RESULTS");?></a></p>';
					}
					suggest += '<p style="position:absolute;bottom:5px;cursor:pointer;right:10px;padding:2px;margin:0px auto;" onclick="javascript:closeSearch<?php echo $module->id;?>();"><img src="<?php echo JURI::root();?>modules/mod_rssearch/assets/images/close.png" alt="" /></p>';
					<?php echo (JPluginHelper::isEnabled('system','mtupgrade') || modRSSearchHelper::isJ16() ? "ss.set('html',suggest);" : "ss.setHTML(suggest);");?>
					RSFSearch<?php echo $module->id;?>.slideIn();
				}
			}
		}; 
		searchReq.send(null);
	}
}

function suggestOver<?php echo $module->id;?>(div_value){
	div_value.className = 'suggest_link_over';
}

function suggestOut<?php echo $module->id;?>(div_value){
	div_value.className = 'suggest_link';
}

function setSearch<?php echo $module->id;?>(value){
	document.getElementById('search_suggest<?php echo $module->id;?>').innerHTML = '';
	document.getElementById('frmSearch'+<?php echo $module->id;?>).submit();
}
function closeSearch<?php echo $module->id;?>(){
	RSFSearch<?php echo $module->id;?>.slideOut();
}

window.addEvent('domready', function(){
	$('search_suggest<?php echo $module->id;?>').setStyle('height','auto');
	RSFSearch<?php echo $module->id;?> = new Fx.Slide('search_suggest<?php echo $module->id;?>').hide();
	var parent = $('search_suggest<?php echo $module->id;?>').getParent('div').setStyle('width','<?php echo $box_width;?>px');
});
</script>

<div id="rssearch<?php echo $class_suffix; ?>" class="rssearch_box">
	<form id="frmSearch<?php echo $module->id;?>" action="<?php echo JRoute::_('index.php')?>" method="GET" accept-charset="utf-8" class="rsf_form">

		<input type="hidden" name="option" value="com_rssearch" />
		<input type="hidden" name="view" value="results" />
		<input type="hidden" name="layout" value="default" />
		<input type="hidden" name="module_id" value="<?php echo $module->id;?>" />
		<input type="text" id="rsf_inp<?php echo $module->id;?>" name="search" alt="Enter keywords" onkeyup="searchSuggest<?php echo $module->id;?>();" autocomplete="off" style="width:<?php echo $field_width;?>px" />

		<?php if($show_btn == 'yes'){ ?> <input type="submit" id="cmdSearch" name="cmdSearch" value="<?php echo JText::_('RSF_MODULE_SEARCH_BTN');?>" /><?php }?>
		<input type="hidden" name="Itemid" value="<?php echo $itemid;?>" />
		<br />

		<div id="search_suggest<?php echo $module->id;?>" class="rsfsuggestions" style="width:<?php echo $box_width;?>px">

		</div>
	</form>
</div>
